package com.invengo.module_check.ui.fragment.remove;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.Nullable;

import com.afollestad.materialdialogs.MaterialDialog;
import com.invengo.module_check.BR;
import com.invengo.module_check.R;
import com.invengo.module_check.databinding.FragmentRemoveOldBinding;

import me.goldze.mvvmhabit.base.BaseFragment;
import me.goldze.mvvmhabit.utils.MaterialDialogUtils;

public class RemoveOldFragment extends BaseFragment<FragmentRemoveOldBinding, RemoveOldViewModel> {
    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_remove_old;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }
    private MaterialDialog removeDialog;
    @Override
    public void initViewObservable() {
        viewModel.ui.removeBookEvent.observe(this, bookBeans -> {
            if (removeDialog == null)
                removeDialog = MaterialDialogUtils.showBasicDialog(getActivity(), "温馨提醒!", "剔旧将从数据库删除图书数据，确定剔旧？")
                        .positiveText("确定")
                        .negativeText("取消")
                        .onPositive((dialog, which) -> {
                            viewModel.insertBookDeleteLogs(bookBeans);
                        })
                        .onNegative((dialog, which) -> {
                        }).build();
            if (!removeDialog.isShowing())
                removeDialog.show();
        });
    }
}
